﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Xml.Linq;
using StrategicDataSystems.Cloud.Monitoring.HostedServices.ResponseToEntityMappers;

namespace StrategicDataSystems.Cloud.Monitoring.Tests.Given_A_HostedServiceListResponseMapper
{
    [TestFixture]
    public class When_Convert_To_Entity_IsCalled
    {

        [Test]
        public void Should_Return_A_List_Of_ServiceMangementUrls()
        {
            IEnumerable<string> expectedResult = new string[] { 
                    "https://management.core.windows.net/DDB588AB-F97D-4014-85EF-6FC476341FCF/services/hostedservices/service1", 
                    "https://management.core.windows.net/DDB588AB-F97D-4014-85EF-6FC476341FCF/services/hostedservices/service2" 
            };

            XDocument testResponse = XDocument.Parse(
                @"<HostedServices xmlns='http://schemas.microsoft.com/windowsazure' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>
                      <HostedService>
                        <Url>https://management.core.windows.net/DDB588AB-F97D-4014-85EF-6FC476341FCF/services/hostedservices/service1</Url>
                        <ServiceName>service1</ServiceName>
                      </HostedService>
                      <HostedService>
                        <Url>https://management.core.windows.net/DDB588AB-F97D-4014-85EF-6FC476341FCF/services/hostedservices/service2</Url>
                        <ServiceName>service2</ServiceName>
                      </HostedService>
                  </HostedServices>"
                );


            HostedServiceListResponseMapper mapper = new HostedServiceListResponseMapper();
            IEnumerable<string> mappingResult = mapper.MapToEntity(testResponse);

            CollectionAssert.AreEquivalent(expectedResult, mappingResult);                             
        }

        [Test]
        public void Should_Return_An_Empty_Result_If_No_Services_Are_Present()
        {

            IEnumerable<string> expectedResult = new string[] {} ;

            XDocument testResponse = XDocument.Parse(
                @"<HostedServices xmlns='http://schemas.microsoft.com/windowsazure' xmlns:i='http://www.w3.org/2001/XMLSchema-instance' />");

            HostedServiceListResponseMapper mapper = new HostedServiceListResponseMapper();
            IEnumerable<string> mappingResult = mapper.MapToEntity(testResponse);

            CollectionAssert.AreEquivalent(expectedResult, mappingResult);       
        }

    }
}
